#include "../configManager/ConfigManager.h"
#include "../logManager/LogManager.h"
#include "../exceptionManager/ExceptionManager.h"
#include <iostream>
#include <thread>

#define CONFIG_PATH "config/config.json"

int main()
{
    LogManager::getInstance().init("./logs/");
    LogManager::getInstance().log("System", "SmartHome started");

    // 配置使用
    ConfigManager::getInstance().set("device1", "on");
    ConfigManager::getInstance().saveConfig(CONFIG_PATH);
    ConfigManager::getInstance().loadConfig(CONFIG_PATH);
    std::cout << "Device1: " << ConfigManager::getInstance().get("device1") << std::endl;

    // 异常处理演示
    try
    {
        throw std::runtime_error("Cannot connect to database");
    }
    catch (const std::exception &e)
    {
        ExceptionManager::handle("Database", e);
    }

    std::this_thread::sleep_for(std::chrono::seconds(1));
    LogManager::getInstance().flush(); // 程序结束前刷新日志
    return 0;
}
